<?php
/**
 * Created by PhpStorm.
 * User: River
 * Email: river0428@gmail.com
 * Date: 2018/11/13
 * Time: 下午2:06
 */

namespace Modules\Wap\Controllers;

use App\Models\Activity;
use App\Models\Configure;
use App\Models\Page;
use App\Models\Recharge;
use Illuminate\Http\Request;

class TopicController extends Controller
{
    public function page($name)
    {
        $page = Page::where('name', $name)->first();
        return view('wap::topic', ['page' => $page]);
    }

    public function html($name)
    {
        $data['recharge'] = Recharge::orderBy('discount', 'desc')->get();

        if ($name == 'about') {
            return header('Location: http://h5.wenhuakj.com/about');
        }
        // share_title=xxx&share_desc=xxx&share_img=xxx&share_link=xxx
        $shareUrl = 'redirect://oilcard:8888/share?';
        $shareUrl = $shareUrl . 'share_title=' . urlencode(Configure::getByKey('share_title'));
        $shareUrl = $shareUrl . '&share_desc=' . urlencode(Configure::getByKey('share_desc'));
        $shareUrl = $shareUrl . '&share_img=' . urlencode(Configure::getByKey('share_img'));
        $shareUrl = $shareUrl . '&share_link=' . urlencode(Configure::getByKey('share_link'));
        $data['shareUrl'] = $shareUrl;

        if ($name == 'find') {
            $data['activities'] = Activity::with('image')->orderBy('end_at', 'desc')->get();
        }

        return view('wap::' . $name, $data);
    }
}